package servlet.admin;

import dao.WarningRecordDAO;
import entity.WarningRecord;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/admin/records")
public class WarningRecordServlet extends HttpServlet {
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 查询所有预警记录
        List<WarningRecord> records = WarningRecordDAO.getAllWarningRecords();
        System.out.println("Records size: " + records.size()); // 打印记录的大小

        // 将结果传递到 JSP 页面
        request.setAttribute("records", records);
        RequestDispatcher dispatcher = request.getRequestDispatcher("/admin/records.jsp");
        dispatcher.forward(request, response);
    }

}
